package live.common;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServlet;

public class ReadCodeName extends HttpServlet {
	
	public static Map cityHashMap;
	public static Map aircomHashMap;
	public static Map flightHashMap;
	
	static{
		if(cityHashMap==null){
			Properties prop = new Properties();
			FileInputStream inStream;
			try {
				inStream = new FileInputStream(ReadCodeName.class.getResource("/citycode_zh.properties").getPath());
				prop.load(inStream);
				Enumeration enu = prop.propertyNames();
				cityHashMap = new HashMap();
				while (enu.hasMoreElements()) {
					String key = (String)enu.nextElement();
					cityHashMap.put(key, prop.get(key));
				}
				inStream = new FileInputStream(ReadCodeName.class.getResource("/aircom_zh.properties").getPath());
				prop.load(inStream);
				aircomHashMap=new HashMap();
				Enumeration aircomenu = prop.propertyNames();
				while (aircomenu.hasMoreElements()) {
					String key = (String)aircomenu.nextElement();
					aircomHashMap.put(key, prop.get(key));
				}
				inStream = new FileInputStream(ReadCodeName.class.getResource("/flightname_zh.properties").getPath());
				prop.load(inStream);
				Enumeration flightenu = prop.propertyNames();
				flightHashMap=new HashMap();
				while (flightenu.hasMoreElements()) {
					String key = (String)flightenu.nextElement();
					flightHashMap.put(key, prop.get(key));
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
}
